import java.util.ArrayList;
import java.util.Random;

public class Test
{
    public static void main(String[] args) {
        String getcode = getcode();
        System.out.println(getcode);
    }
    private static String getcode() {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            list.add((char) ('a' + i));
            list.add((char) ('A' + i));
        }
        //随机获得4个验证码
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 4; i++) {
            Random r = new Random();
            //获取随机索引
            int index = r.nextInt(list.size());
            char c = list.get(index);//获取当前索引对应的字符
            sb.append(c);//字符串拼接
        }
        //获取最后一个数字
        Random r=new Random();
        int number=r.nextInt(10);
        sb.append(number);
        char[] arr = sb.toString().toCharArray();
        int index = r.nextInt(arr.length);
        char tmp = arr[index];
        arr[index] = arr[(arr.length)-1];
        arr[(arr.length)-1] = tmp;
        return new String(arr);
    }
}
